package cn.zjn.test.springboot.controller;

import cn.zjn.test.springboot.domain.Page;
import cn.zjn.test.springboot.service.HResourcesService;
import cn.zjn.test.springboot.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Author: Zjn *Bring it on!!!*
 * @Date: 2021/1/31 14:50
 * Note:首页资源
 */
@RestController
public class HomeResourcesController {
    @Autowired
    HResourcesService hResourcesService;

    @GetMapping("/getTask")         //首页展示项目进度
    public JsonResult getTask(@RequestParam Integer amount,@RequestParam(defaultValue = "5") Integer limit) throws ParseException {
        System.out.println("------------------");
        HashMap<Object, Object> hashMap = new HashMap<>();
        List<Map<String, Object>> task2 = hResourcesService.getTask(new Page(amount, limit));
        for (int i = 0; i <task2.size() ; i++) {
            hashMap.put(i,task2.get(i));
        }
        return new JsonResult(hashMap);
    }

    @GetMapping("/getLast")
    public JsonResult getLast(@RequestParam Integer amount,@RequestParam(defaultValue = "5") Integer limit){
        return new JsonResult(hResourcesService.getLast(new Page(amount,limit)));
    }
}
